<?php
require_once 'bootstrap.php';

$sports = $my_db->select('SELECT * FROM sports');
$sport_names = $my_db->select_pairs('SELECT * FROM sports');
$zipcode = $_GET['zipcode'];
$leagues = $my_db->select_col('SELECT sport FROM leagues WHERE zipcode = ?', array($zipcode));
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title><?php echo $front_title; ?></title>
<?php include("__head_tag.php");?>
</head>
<body>
<div id="wrap">
<?php include("__header.php"); ?>

<?php include("__nav.php"); ?>

<div id="content">
  <p>&nbsp;</p>
<h2>Zipcode Results </h2>
<p>
	<div align="center">Youth sports available in <?=$zipcode?></div>
    <br />
    <table width="100%" border="0" cellspacing="1" cellpadding="1">
	    <?php
			$count = 1;
	        $icon = '';
	        $name = '';
	        foreach ($sports as $sport):
		        if (in_array($sport['id'], $leagues)){
			        $href ='sports_results.php?id='.$sport['id'].'&zipcode='.$zipcode;
			        $icon .= '<td class="sportBox" ><a href = "'.$href.'"><img width="58" height="58" src="__admin/'.$sport['image_on'].'" alt="" /></a></td>';
			        $name .= '<td class="sportName"><a href = "'.$href.'">'.$sport['name'].'</a></td>';
		        }else{
			        $icon .= '<td class="sportBox" title="This sports is not available in '.$zipcode.'"><img width="58" height="58" src="__admin/'.$sport['image_off'].'" title="This sports is not available in '.$zipcode.'" /></td>';
			        $name .= '<td class="sportName">'.$sport['name'].'</td>';
		        }

		        if ($count % 10 ==0){
			        echo '<tr>'.$icon.'</tr>'.'<tr>'.$name.'</tr>'.'<tr><td colspan="10">&nbsp;</td></tr>';
			        $icon = '';
			        $name = '';
		        }
		        $count++;
	    ?>
      <?php endforeach;

	    echo '<tr>'.$icon.'</tr>'.'<tr>'.$name.'</tr>'.'<tr><td colspan="10">&nbsp;</td></tr>';
	    ?>
               
    </table>
    </p>
</div>
<?php include("__footer.php"); ?>
</div>
</body>
</html>